package xijia.plus.docs.manage.all.controller;

import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.base.model.BasePage;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.manage.sys.model.query.ConfigQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import xijia.plus.docs.constant.RequestConst;
import xijia.plus.docs.manage.all.model.dto.DocConfigDTO;
import xijia.plus.docs.manage.all.model.vo.DocConfigVO;
import xijia.plus.docs.manage.all.service.DocConfigService;

import java.util.Set;

/**
 * 系统全局配置 前端控制器
 *
 * <p>
 * ::本代码由[兮家小二]提供的代码生成器生成,如有问题,请手动修改 ::作者CSDN:https://blog.csdn.net/qq_41463655
 * </p>
 *
 * @author ws
 * @email 1720696548@qq.com
 * @date 2023-04-23 11:02:52
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/all/docConfig")
@Api(value = "DocConfigController", tags = "系统全局配置")
public class DocConfigController extends BaseController<DocConfigService> {


    @GetMapping(value = "/findPage")
    @ApiOperation(value = "分页查询")
    public Result<BasePage<DocConfigVO>> findPage(@ModelAttribute @Validated ConfigQuery query) {
        return Result.success(baseService.findPage(request.getHeader(RequestConst.DB), query));
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value = "ID查询")
    public Result<DocConfigVO> findId(@PathVariable String id) {
        return Result.successUpdate(baseService.findId(request.getHeader(RequestConst.DB), id));
    }


    @PostMapping
    @ApiOperation(value = "添加")
    public Result<String> insert(@RequestBody @Validated DocConfigDTO dto) {
        return Result.successInsert(baseService.insert(request.getHeader(RequestConst.DB), dto));
    }


    @PutMapping(value = "/{id}")
    @ApiOperation(value = "ID编辑")
    public Result<Boolean> upd(@PathVariable String id, @RequestBody @Validated DocConfigDTO dto) {
        return Result.successUpdate(baseService.upd(request.getHeader(RequestConst.DB), id, dto));
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "ID删除")
    public Result<Boolean> del(@PathVariable String id) {
        return Result.successDelete(baseService.del(request.getHeader(RequestConst.DB), id));
    }


    @RequestMapping(value = "/findByCode", method = RequestMethod.GET)
    @ApiOperation(value = "CODE查询")
    public Result<DocConfigVO> findByCode(@RequestParam String code) {
        return Result.successFind(baseService.findByCode(request.getHeader(RequestConst.DB), code));
    }


    @GetMapping(value = "/getTenantNames")
    @ApiOperation(value = "查询租户")
    public Result<Set<String>> getTenantNames() {
        return Result.success(baseService.getTenantNames());
    }
}
